# -*- coding: utf-8 -*-
import unittest
from structures.heap import Heap


class HeapTest(unittest.TestCase):

    def test_add_n_elements_verify_order(self):
        heap = Heap()
        n = 65
        #Insert elements in reverse order
        for i in range(n):
            heap.insert(n - i, n - i)

        #Then verify they are extracted from min to max
        min = None
        while not heap.empty():
            newmin = heap.extract_min()
            if min is not None:
                self.assertLessEqual(min, newmin)
            min = newmin

    def test_add_3_elements_change_key_verify_heap_order(self):
        heap = Heap()
        n = 3
        #Insert elements in reverse order
        for i in range(n):
            heap.insert(n - i, n - i)

        heap.change_data(0, 4)
        heap.change_key(0, 4)

        #Then verify they are extracted from min to max
        min = None
        while not heap.empty():
            newmin = heap.extract_min()
            if min is not None:
                self.assertLessEqual(min, newmin)
            min = newmin
